<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1" xml:lang="en">
  <title id="gh143896">pg_constraint</title>
  <body>
    <p>The <codeph>pg_constraint</codeph> system catalog table stores check, primary key, unique,
      and foreign key constraints on tables. Column constraints are not treated specially. Every
      column constraint is equivalent to some table constraint. Not-null constraints are represented
      in the <xref href="pg_attribute.xml#topic1">pg_attribute</xref> catalog table. Check
      constraints on domains are stored here, too.</p>
    <table id="gh143898">
      <title>pg_catalog.pg_constraint</title>
      <tgroup cols="4">
        <colspec colnum="1" colname="col1" colwidth="131pt"/>
        <colspec colnum="2" colname="col2" colwidth="69.75pt"/>
        <colspec colnum="3" colname="col3" colwidth="99.75pt"/>
        <colspec colnum="4" colname="col4" colwidth="147pt"/>
        <thead>
          <row>
            <entry colname="col1">column</entry>
            <entry colname="col2">type</entry>
            <entry colname="col3">references</entry>
            <entry colname="col4">description</entry>
          </row>
        </thead>
        <tbody>
          <row>
            <entry colname="col1">
              <codeph>conname</codeph>
            </entry>
            <entry colname="col2">name</entry>
            <entry colname="col3"/>
            <entry colname="col4">Constraint name (not necessarily unique!)</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>connamespace</codeph>
            </entry>
            <entry colname="col2">oid</entry>
            <entry colname="col3">pg_namespace.oid</entry>
            <entry colname="col4">The OID of the namespace (schema) that contains this
              constraint.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>contype </codeph>
            </entry>
            <entry colname="col2">char</entry>
            <entry colname="col3"/>
            <entry colname="col4"><codeph>c</codeph> = check constraint, <codeph>f</codeph> =
              foreign key constraint, <codeph>p</codeph> = primary key constraint,
                <codeph>u</codeph> = unique constraint.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>condeferrable</codeph>
            </entry>
            <entry colname="col2">boolean</entry>
            <entry colname="col3"/>
            <entry colname="col4">Is the constraint deferrable?</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>condeferred </codeph>
            </entry>
            <entry colname="col2">boolean </entry>
            <entry colname="col3"/>
            <entry colname="col4">Is the constraint deferred by default?</entry>
          </row>
          <row>
            <entry><codeph>convalidated</codeph></entry>
            <entry>boolean</entry>
            <entry/>
            <entry>Has the constraint been validated? Currently, can only be false for foreign
              keys</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>conrelid</codeph>
            </entry>
            <entry colname="col2">oid</entry>
            <entry colname="col3">pg_class.oid</entry>
            <entry colname="col4">The table this constraint is on; 0 if not a table
              constraint.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>contypid </codeph>
            </entry>
            <entry colname="col2">oid</entry>
            <entry colname="col3">pg_type.oid</entry>
            <entry colname="col4">The domain this constraint is on; 0 if not a domain
              constraint.</entry>
          </row>
          <row>
            <entry><codeph>conindid</codeph></entry>
            <entry>oid</entry>
            <entry>pg_class.oid</entry>
            <entry>The index supporting this constraint, if it's a unique, primary key, foreign key,
              or exclusion constraint; else 0</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>confrelid</codeph>
            </entry>
            <entry colname="col2">oid</entry>
            <entry colname="col3">pg_class.oid</entry>
            <entry colname="col4">If a foreign key, the referenced table; else 0.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>confupdtype</codeph>
            </entry>
            <entry colname="col2">char</entry>
            <entry colname="col3"/>
            <entry colname="col4">Foreign key update action code.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>confdeltype</codeph>
            </entry>
            <entry colname="col2">char</entry>
            <entry colname="col3"/>
            <entry colname="col4">Foreign key deletion action code.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>confmatchtype</codeph>
            </entry>
            <entry colname="col2">char</entry>
            <entry colname="col3"/>
            <entry colname="col4">Foreign key match type.</entry>
          </row>
          <row>
            <entry><codeph>conislocal</codeph></entry>
            <entry>boolean</entry>
            <entry/>
            <entry>This constraint is defined locally for the relation. Note that a constraint can
              be locally defined and inherited simultaneously.</entry>
          </row>
          <row>
            <entry><codeph>coninhcount</codeph></entry>
            <entry>int4</entry>
            <entry/>
            <entry>The number of direct inheritance ancestors this constraint has. A constraint with
              a nonzero number of ancestors cannot be dropped nor renamed.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>conkey</codeph>
            </entry>
            <entry colname="col2">int2[]</entry>
            <entry colname="col3">pg_attribute.attnum</entry>
            <entry colname="col4">If a table constraint, list of columns which the constraint
              constrains.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>confkey</codeph>
            </entry>
            <entry colname="col2">int2[]</entry>
            <entry colname="col3">pg_attribute.attnum</entry>
            <entry colname="col4">If a foreign key, list of the referenced columns.</entry>
          </row>
          <row>
            <entry><codeph>conpfeqop</codeph></entry>
            <entry>oid[]</entry>
            <entry>pg_operator.oid</entry>
            <entry>If a foreign key, list of the equality operators for PK = FK comparisons.</entry>
          </row>
          <row>
            <entry><codeph>conppeqop</codeph></entry>
            <entry>oid[]</entry>
            <entry>pg_operator.oid</entry>
            <entry>If a foreign key, list of the equality operators for PK = PK comparisons.</entry>
          </row>
          <row>
            <entry><codeph>conffeqop</codeph></entry>
            <entry>oid[]</entry>
            <entry>pg_operator.oid</entry>
            <entry>If a foreign key, list of the equality operators for PK = PK comparisons.</entry>
          </row>
          <row>
            <entry><codeph>conexclop</codeph></entry>
            <entry>oid[]</entry>
            <entry>pg_operator.oid</entry>
            <entry>If an exclusion constraint, list of the per-column exclusion operators.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>conbin</codeph>
            </entry>
            <entry colname="col2">text </entry>
            <entry colname="col3"/>
            <entry colname="col4">If a check constraint, an internal representation of the
              expression.</entry>
          </row>
          <row>
            <entry colname="col1">
              <codeph>consrc</codeph>
            </entry>
            <entry colname="col2">text</entry>
            <entry colname="col3"/>
            <entry colname="col4">If a check constraint, a human-readable representation of the
              expression. This is not updated when referenced objects change; for example, it won't
              track renaming of columns. Rather than relying on this field, it is best to use
                <codeph>pg_get_constraintdef()</codeph> to extract the definition of a check
              constraint.</entry>
          </row>
        </tbody>
      </tgroup>
    </table>
  </body>
</topic>
